In [1]:
import plotly as py

py.offline.init_notebook_mode() # run at the start of every notebook
py.offline.iplot({
"data": [{
    "x": [1, 2, 3],
    "y": [4, 2, 5]
}],
"layout": {
    "title": "hello world"
}
})         # version 1.9.4 required
In [15]:
import plotly.graph_objs as go

# Create random data with numpy
import numpy as np

N = 1000
random_x = np.random.randn(N)
random_y = np.random.randn(N)

# Create a trace
trace = go.Scatter(
    x = random_x,
    y = random_y,
    mode = 'markers'
)

data = [trace]

# Plot and embed in ipython notebook!
py.offline.iplot(data)
In [14]:
from plotly.graph_objs import *

import numpy as np

s = np.linspace(0, 2 * np.pi, 240)
t = np.linspace(0, np.pi, 240)
tGrid, sGrid = np.meshgrid(s, t)

r = 2 + np.sin(7 * sGrid + 5 * tGrid)  # r = 2 + sin(7s+5t)
x = r * np.cos(sGrid) * np.sin(tGrid)  # x = r*cos(s)*sin(t)
y = r * np.sin(sGrid) * np.sin(tGrid)  # y = r*sin(s)*sin(t)
z = r * np.cos(tGrid)                  # z = r*cos(t)

surface = Surface(x=x, y=y, z=z)
data = Data([surface])

layout = Layout(
    title='Parametric Plot',
    scene=Scene(
        xaxis=XAxis(
            gridcolor='rgb(255, 255, 255)',
            zerolinecolor='rgb(255, 255, 255)',
            showbackground=True,
            backgroundcolor='rgb(230, 230,230)'
        ),
        yaxis=YAxis(
            gridcolor='rgb(255, 255, 255)',
            zerolinecolor='rgb(255, 255, 255)',
            showbackground=True,
            backgroundcolor='rgb(230, 230,230)'
        ),
        zaxis=ZAxis(
            gridcolor='rgb(255, 255, 255)',
            zerolinecolor='rgb(255, 255, 255)',
            showbackground=True,
            backgroundcolor='rgb(230, 230,230)'
        )
    )
)

fig = Figure(data=data, layout=layout)
py.offline.iplot(fig)
In [ ]:
from IPython.core.display import HTML
import d3_lib, random
In [3]:
%matplotlib inline
from IPython.core.display import HTML
import d3_lib
In [5]:
HTML(d3_lib.set_styles(['basic_axis','3d_viewer']))
Out[5]:
In [6]:
HTML('<script src="lib/d3/d3.min.js"></script>')
Out[6]:
In [8]:
def points_d3(points):
    return [ {"x": d[0], "y": d[1], "z": d[2]} for d in points ]

def triangles_d3(points,triangles_vertices):
    triangles = []
    for tv in triangles_vertices:
        triangles.append( {"x1": points[tv[0]][0], 
                           "y1": points[tv[0]][1], 
                           "z1": points[tv[0]][2], 
                           "x2": points[tv[1]][0], 
                           "y2": points[tv[1]][1], 
                           "z2": points[tv[1]][2], 
                           "x3": points[tv[2]][0], 
                           "y3": points[tv[2]][1], 
                           "z3": points[tv[2]][2] } )
    
    return triangles

def graph_points_triangles(objs):
    data = []
    for obj in objs:
        points, triangles_vertices = obj[0], obj[1]
        data.append( {"points": points_d3(points), 
                      "triangles": triangles_d3(points, triangles_vertices)} )
    return HTML(d3_lib.draw_graph('3d_viewer',{'data':data}))
In [10]:
from IPython.core.display import display, HTML
from string import Template
import pandas as pd
import json, random
In [12]:
random.seed(42)

n_nodes = 40
n_edges = 200

graph_data = { 'nodes': [], 'edges': [] }

for i in range(n_nodes):
    graph_data['nodes'].append({
            "id": "n" + str(i),
            "label": "n" + str(i),
            "x": random.uniform(0,1),
            "y": random.uniform(0,1),
            "size": random.uniform(0.2,1)
        })

for j in range(n_edges):
    x_center = random.uniform(0,1)
    y_center = random.uniform(0,1)
    x_dist = random.uniform(0.1,0.5)
    y_dist = random.uniform(0.2,0.5)
    neighborhood = []
    for node in graph_data['nodes']:
        if abs(node['x'] - x_center) < x_dist:
            if abs(node['y'] - y_center) < y_dist:
                neighborhood.append(int(node['id'].replace('n','')))
    if len(neighborhood) >= 2:
        ends = random.sample(neighborhood,2)
        graph_data['edges'].append({
                "id": "e" + str(j),
                "source": "n" + str(ends[0]),
                "target": "n" + str(ends[1])
            })
In [14]:
HTML('''
<script src="lib/sigmajs/sigma.min.js"></script>
<script src="js/sigma-add-method-neighbors.js"></script>
''')
Out[14]:
In [15]:
js_text_template = Template(open('js/sigma-graph.js','r').read())

js_text = js_text_template.substitute({'graph_data': json.dumps(graph_data),
                                       'container': 'graph-div'})

html_template = Template('''
<div id="graph-div" style="height:400px"></div>
<script> $js_text </script>
''')
HTML(html_template.substitute({'js_text': js_text}))
Out[15]:
In [16]:
from ipywidgets import widgets
from __future__ import print_function
from ipywidgets import interact, interactive, fixed
import ipywidgets as widgets
In [17]:
def f(x):
    return x
In [18]:
interact(f, x=10);
11
In [ ]:
!ipython nbconvert  --to html Test.ipynb